<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container >
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>

          <a-col :span="16">
            <a-form-model-item label="用户状态是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isWaterUserStatus">
              <j-dict-select-tag type="radioButton" v-model="model.isWaterUserStatus" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="用户状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waterUserStatus">
              <j-dict-select-tag type="list" v-model="model.waterUserStatus" dictCode="water_user_status" placeholder="请选择用户状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item label="用水性质是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isNatureId">
              <j-dict-select-tag type="radioButton" v-model="model.isNatureId" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
           <a-form-model-item label="用水性质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="natureId">
  	          <j-tree-select
                ref="treeSelect"
                placeholder="请选择用水性质"
                v-model="model.natureId"
                dict="mws_t_base_natures,name,id"
                pidValue="0"
                >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item label="水表用途是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isWaterUseType">
              <j-dict-select-tag type="radioButton" v-model="model.isWaterUseType" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="水表用途" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waterUseType">
              <j-dict-select-tag type="list" v-model="model.waterUseType" dictCode="water_use_type" placeholder="请选择水表用途" />
            </a-form-model-item>
          </a-col>

          <a-col :span="16">
            <a-form-model-item label="抄表周期是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isWaterReadCycle">
              <j-dict-select-tag type="radioButton" v-model="model.isWaterReadCycle" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="抄表周期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="waterReadCycle">
              <j-dict-select-tag type="list" v-model="model.waterReadCycle" dictCode="water_read_cycle" placeholder="请选择抄表周期" />
            </a-form-model-item>
          </a-col>

          <a-col :span="16">
            <a-form-model-item label="本月抄表是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isIsRead">
              <j-dict-select-tag type="radioButton" v-model="model.isIsRead" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="本月是否要抄表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isRead">
              <j-dict-select-tag type="list" v-model="model.isRead" dictCode="yn" placeholder="请选择本月是否要抄表" />
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item label="应抄次数是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isReadTimes">
              <j-dict-select-tag type="radioButton" v-model="model.isReadTimes" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
             <a-form-model-item label="应抄次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="readTimes">
              <a-input-number v-model="model.readTimes" placeholder="请输入应抄次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
           <a-col :span="16">
            <a-form-model-item label="待抄次数是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isUnreadTimes">
              <j-dict-select-tag type="radioButton" v-model="model.isUnreadTimes" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
             <a-form-model-item label="待抄次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unreadTimes">
              <a-input-number v-model="model.unreadTimes" placeholder="请输入待抄次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>  
           <a-col :span="16">
            <a-form-model-item label="应缴费日是否修改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPaidDay">
              <j-dict-select-tag type="radioButton" v-model="model.isPaidDay" dictCode="yn" placeholder="请选择是否修改" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="应缴费日" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paidDay">
              <a-input v-model="model.paidDay" placeholder="请输入应缴费日"  ></a-input>
            </a-form-model-item>
          </a-col> 
        
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ArcBatchForm',
    components: {
    },
    props: ["cusData"],
    
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          // changeCause: [
          //     { required: true, message: '请输入原因!'},
          //  ],           
        },
        url: {
          recoverUrl: "/arc/arcCustomers/addBatch",
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      this.model.cusIds=this.cusData;   
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
        this.model.cusIds=this.cusData;
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {            
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.recoverUrl;
              method = 'post';
            }
            console.log("this.model:",this.model)

            if(this.model.isWaterUserStatus == '1' && !this.model.waterUserStatus){
              that.$message.warning("请选择用户状态");
              return;
            }
            if(this.model.isNatureId == 1 && !this.model.natureId){
              that.$message.warning("请选择用水性质");
              return;
            }
            if(this.model.isWaterUseType == 1 && !this.model.waterUseType){
              that.$message.warning("请选择水表用途");
              return;
            }
            if(this.model.isWaterReadCycle == 1 && !this.model.waterReadCycle){
              that.$message.warning("请选择抄表周期");
              return;
            }

            if(this.model.isIsRead == 1 && !this.model.isRead){
              that.$message.warning("请选择本月是否要抄表");
              return;
            }
            if(this.model.isReadTimes == 1 && !this.model.readTimes){
              that.$message.warning("请输入应抄次数");
              return;
            }
            if(this.model.isUnreadTimes == 1 && !this.model.unreadTimes){
              that.$message.warning("请输入待抄次数");
              return;
            }
            if(this.model.isPaidDay == 1 && !this.model.paidDay){
              that.$message.warning("请输入应缴费日");
              return;
            }
            that.confirmLoading = true;

            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>


<style scoped>
</style>